package com.earl.gsm.web.finance;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.earl.gsm.domain.gsm.finance.FinanceRecord;
import com.earl.gsm.domain.sercurity.user.User;
import com.earl.gsm.service.FinanceRecordService;
import com.earl.gsm.web.BaseController;
import com.wordnik.swagger.annotations.ApiOperation;

@Controller
@RequestMapping(value = "/finance")
//@Api(value="Person Rest Service") //修改生成的son路径
public class FinanceRecordController extends BaseController {

    private final Logger log = LoggerFactory.getLogger(FinanceRecordController.class);

    @Autowired
    private FinanceRecordService service;

    /**
     * GET /users -> get all the users
     */
    @RequestMapping(value = "/all")
    @ApiOperation(value = "得到所有的申请信息", notes = "find All User", httpMethod = "GET", response = User.class, responseContainer = "List")
    public ModelAndView getAll() {
        log.debug("page show all apply for create match");
        return new ModelAndView("finance/allFinance","financeList",service.findAll());
    }
    
    @RequestMapping(value = "/countRate")
    public ModelAndView countRate(String minDate,String maxDate){
    	
    		List<FinanceRecord> tmp = service.countRate(minDate, maxDate);
    		List<Double> dataprice = new ArrayList<Double>();
    		List<String> title = new ArrayList<String>();
    		for (FinanceRecord financeRecord : tmp) {
    				dataprice.add(financeRecord.getPrice());
    				title.add("\""+financeRecord.getPrice()+"(price)   %%.%% –"+financeRecord.getConsumeType()+"\"");
    		}
    		Map dodo = new HashMap();
    		dodo.put("dataprice", dataprice.toString());
    		dodo.put("title", title.toString());
    	return new ModelAndView("finance/piechart","map",dodo);
    }
    
    @RequestMapping(value = "/searchChart")
    public String searchRate(){
    	return "finance/searchChart";
    }
}
